import { constantRoutes } from '@/router'

const state = {
  routes: []  // 存储最终的路由
}

const mutations = {
  SET_ROUTES: (state, routes) => {
    state.routes = routes
    console.log(state.routes, 'Updated routes') // 可以检查 routes 是否正确设置
  }
}

const actions = {
  generateRoutes({ commit }) {
    return new Promise(resolve => {
      // 直接使用 constantRoutes 作为路由配置
      const accessedRoutes = constantRoutes
      commit('SET_ROUTES', accessedRoutes)
      resolve(accessedRoutes) // 返回访问的路由
    })
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
